package com.java.demo.controller;

import com.java.demo.User;
import com.java.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

@Controller
public class UserController {

//    @Autowired
//    @Qualifier("user2")
//    private User user;
    private UserService userService;
    //通过@Resouce注入
    @Resource(name="user1",type = User.class)
    private User user;

    //属性注入
//    @Autowired
//    private UserService userService;

//    //setter方法注入
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

     //构造方法注入
     @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void sayHi() {
        System.out.println(user);
        userService.sayHi();
//        System.out.println("我是UserController");
    }

}
